import 'package:auto_route/auto_route.dart';
import 'package:distribution_mall_flutter/constant/cf_constant.dart';
import 'package:distribution_mall_flutter/constant/constant.dart';
import 'package:distribution_mall_flutter/constant/status_constant.dart';
import 'package:distribution_mall_flutter/entity/order/detail/order_detail_entity.dart';
import 'package:distribution_mall_flutter/pages/order/order_detail/application/order_detail_service.dart';
import 'package:distribution_mall_flutter/pages/order/widgets/address_card.dart';
import 'package:distribution_mall_flutter/pages/order/widgets/goods_card.dart';
import 'package:distribution_mall_flutter/pages/order/widgets/order_footer.dart';
import 'package:distribution_mall_flutter/pages/order/widgets/order_num.dart';
import 'package:distribution_mall_flutter/pages/order/widgets/pay_cart.dart';
import 'package:distribution_mall_flutter/pages/order/widgets/summary_card.dart';
import 'package:distribution_mall_flutter/provider/order/order_detail.dart';
import 'package:distribution_mall_flutter/router/route_utils.dart';
import 'package:distribution_mall_flutter/utils/common_widget.dart';
import 'package:distribution_mall_flutter/widgets/shimmer.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'widget/merchant_auth_card.dart';

@RoutePage()
class OrderDetailPage extends ConsumerStatefulWidget {
  final String distributionOrderId;

  const OrderDetailPage(
      {super.key,
      @pathParam required this.distributionOrderId});

  @override
  ConsumerState createState() => _OrderDetailPage();
}

class _OrderDetailPage extends ConsumerState<OrderDetailPage> {
  @override
  Widget build(BuildContext context) {
    ref.watch(orderDetailServiceProvider(widget.distributionOrderId));
    OrderDetailEntity? detail =
        ref.watch(orderDetailProvider.select((value) => value.detal));
    bool loading =
        ref.watch(orderDetailProvider.select((value) => value.loading));
    return Scaffold(
        backgroundColor: ColorConstant.pageGreyBg,
        appBar: AppBar(
          leading: CommonBtnWidget.arrowBack(onPressed: () {
            RouteUtils.back();
          }),
          title: Text(detail?.state != null
              ? OrderStatusEnum.getStatusText(detail?.state)
              : ''),
          centerTitle: true,
          titleSpacing: 0,
        ),
        bottomNavigationBar: OrderFooter(
          distributionOrderId: widget.distributionOrderId,
        ),
        body: EPShimmer(
            enabled: loading,
            child: Stack(
              children: [
                SingleChildScrollView(
                  child: Column(
                    children: [
                      const AddressCard(),
                      const MerchantAuthCard(),
                      (loading
                          ? Container(
                              height: 200,
                              color: Colors.white,
                            )
                          : const SizedBox.shrink()),
                      ...(detail?.orderItemGroupList
                              ?.map((item) => GoodsCard(data: item))
                              .toList() ??
                          []),
                      // PromoCard(),
                      const PayCart(),
                      const SummaryCard(),
                      const OrderNum(),
                      Container(
                        height: 80,
                        color: ColorConstant.pageGreyBg,
                      ),
                    ],
                  ),
                ),
              ],
            )
            // SizedBox.expand(
            //     child: Stack(
            //   children: [
            //     Expanded(
            //         child: )
            //   ],
            // )),
            ));
  }
}
